package com.dwxt.race.api;

import com.dwxt.common.annotation.ValidateFiled;
import com.dwxt.common.annotation.ValidateGroup;
import com.dwxt.common.base.BaseResult;
import com.dwxt.race.entity.UserRace;
import com.dwxt.race.entity.vo.UserRaceVo;
import com.dwxt.race.service.RaceService;
import com.dwxt.race.service.UserRaceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/race/api/raceApi")
@RestController
public class RaceApiController {

    @Autowired
    private UserRaceService userRaceService;
    @Autowired
    private RaceService raceService;

    /**
     * showdoc
     * @catalog 赛事/报名
     * @title app报名信息提交
     * @description
     * @param userName string 必选 报名人姓名
     * @param raceId int 必选 赛事id;
     * @param raceName string 必选 赛事名称;
     * @param phone string 必选 电话;
     * @param userId string 必选 移动端用户id;
     * @param status int 可选 当前报名状态;
     * @param age int 必选 年龄;
     * @param sex int 必选 性别;
     * @param documentType int 必选 证件类型;
     * @param certificateNumber string 必选 证件号;
     * @param orderId 可选 string 生成订单id ;
     * @param reason 可选 string;
     * @param physicalCertificateStr 必选 string[] 体检证明
     * @param insuranceCertificateStr 必选 string[] 保险证明
     * @param noteStr 必选 string[] 备注
     * @param remarks 可选 string 备注信息
     * @param registrationStartTime 可选 date 报名开始时间
     * @param registrationEndTime 可选 date 报名结束时间;
     * @param raceStartTime 可选 date 赛事开始时间;
     * @param raceEndTime 可选 date 赛事结束时间;
     * @param conditions 可选 string 报名条件;
     * @param cost 可选 double 报名费用;
     * @param address 可选 string 参赛地址;
     * @param rule 可选 string 比赛规则;
     * @param organizer 可选 string 主办方;
     * @param phone 可选 string 联系电话;
     * @param raceStatus 可选 int 赛事状态;
     * @param integral 可选 int 赛事可得积分;
     * @param maxPerson 可选 int 最大参赛人数;
     * @param registeredNumber 可选 int 已报名人数;
     * @url /race/api/raceApi/createInfo
     * @return {"status":200,"msg":"SUCCESS","data":null}
     */
    @RequestMapping("/createInfo")
    @ValidateGroup(fileds = {
            @ValidateFiled(index = 0, filedName = "phone", regStr = "^1[3|4|5|6|7|8|9][0-9]\\d{4,8}$"),
            @ValidateFiled(index = 0, filedName = "userName", notNull = true),
            @ValidateFiled(index = 0, filedName = "raceId", notNull = true),
            @ValidateFiled(index = 0, filedName = "age", notNull = true),
            @ValidateFiled(index = 0, filedName = "sex", notNull = true),
    })
    public BaseResult createInfo(UserRaceVo userRaceVo){
        return userRaceService.createInfo(userRaceVo);
    }

    /**
     * showdoc
     * @catalog 赛事/支付
     * @title app报名支付
     * @description 报名支付
     * @param userRaceId 必选 int 报名信息id
     * @param payType 必选 int 支付方式 支持支付宝1  微信2
     * @url /race/api/raceApi/payForRace
     * @return {"status":200,"msg":"SUCCESS","data":null}
     */
    @RequestMapping("/payForRace")
    public BaseResult payForRace(Integer userRaceId, Integer payType) throws Exception {
//        return userRaceService.payForRace(userRaceId,payType);
        return userRaceService.payForRaceNew(userRaceId,payType);
    }

    /**
     * showdoc
     * @catalog 赛事/所有赛事列表
     * @title 赛事列表
     * @param pageNum 必选 int
     * @param pageSize 必选 int
     * @param status 可选 int  1.预告；2.报名中；3.进行中；4.已结束 不传返回所有
     * @url /race/api/raceApi/selectRaceList
     * @return {"status":200,"msg":"SUCCESS","data":{"total":1,"list":[{"id":1,"raceName":"测试赛事1","registrationStartTime":"2020-04-12 15:04:32","registrationEndTime":"2020-04-17 15:04:43","raceStartTime":"2020-04-21 15:04:46","raceEndTime":"2020-04-23 15:04:51","conditions":"比赛条件","cost":0.0,"address":"测试地址1","rule":"测试规则","organizer":"测试主办方","phone":"18232256987","createTime":"2020-04-11 15:05:50","updateTime":"2020-04-15 18:43:31","raceStatus":1,"integral":0,"maxPerson":300,"registeredNumber":0,"version":0}],"pageNum":1,"pageSize":10,"size":1,"startRow":1,"endRow":1,"pages":1,"prePage":0,"nextPage":0,"isFirstPage":true,"isLastPage":true,"hasPreviousPage":false,"hasNextPage":false,"navigatePages":8,"navigatepageNums":[1],"navigateFirstPage":1,"navigateLastPage":1,"firstPage":1,"lastPage":1}}
     */
    @RequestMapping("/selectRaceList")
    public BaseResult selectRaceList(@RequestParam(required = true) Integer pageNum,
                                     @RequestParam(required = true)Integer pageSize,
                                     @RequestParam(required = false) Integer status){
        return raceService.selectRaceListFromApp(pageNum,pageSize,status);
    }

    /**
     * showdoc
     * @catalog 赛事/我的赛事
     * @title 我的赛事
     * @param pageNum 必选 int
     * @param pageSize 必选 int
     * @param status 可选 int  1.待参赛；2.历史  不传返回所有
     * @url /race/api/raceApi/selectMyRace
     * @return {"status":200,"msg":"SUCCESS","data":{"total":1,"list":[{"id":1,"userName":"刘鸿飞","raceId":1,"raceName":"测试赛事1","phone":"18233945873","userId":"158502014539731","status":null,"age":18,"sex":0,"documentType":1,"certificateNumber":"500134199213684978","physicalCertificate":"https://ssyerv1.oss-cn-hangzhou.aliyuncs.com/picture/b24250a49f87406ba230dcdf3367ad84.jpg!sswm,http://125.62.47.85:18080/file/M02/00/01/wKgBf16T1G6ACwPsAADIlD__k9003.jpeg","insuranceCertificate":"https://ssyerv1.oss-cn-hangzhou.aliyuncs.com/picture/b24250a49f87406ba230dcdf3367ad84.jpg!sswm,http://125.62.47.85:18080/file/M02/00/01/wKgBf16T1G6ACwPsAADIlD__k9003.jpeg","note":"https://ssyerv1.oss-cn-hangzhou.aliyuncs.com/picture/b24250a49f87406ba230dcdf3367ad84.jpg!sswm,http://125.62.47.85:18080/file/M02/00/01/wKgBf16T1G6ACwPsAADIlD__k9003.jpeg","createTime":null,"updateTime":null,"orderId":null,"reason":null,"physicalCertificateStr":["https://ssyerv1.oss-cn-hangzhou.aliyuncs.com/picture/b24250a49f87406ba230dcdf3367ad84.jpg!sswm","http://125.62.47.85:18080/file/M02/00/01/wKgBf16T1G6ACwPsAADIlD__k9003.jpeg"],"insuranceCertificateStr":["https://ssyerv1.oss-cn-hangzhou.aliyuncs.com/picture/b24250a49f87406ba230dcdf3367ad84.jpg!sswm","http://125.62.47.85:18080/file/M02/00/01/wKgBf16T1G6ACwPsAADIlD__k9003.jpeg"],"noteStr":["https://ssyerv1.oss-cn-hangzhou.aliyuncs.com/picture/b24250a49f87406ba230dcdf3367ad84.jpg!sswm","http://125.62.47.85:18080/file/M02/00/01/wKgBf16T1G6ACwPsAADIlD__k9003.jpeg"],"registrationStartTime":"2020-04-12 15:04:32","registrationEndTime":"2020-04-17 15:04:43","raceStartTime":"2020-04-21 15:04:46","raceEndTime":"2020-04-23 15:04:51","conditions":"比赛条件","cost":0.0,"address":"测试地址1","rule":"测试规则","organizer":"测试主办方","raceStatus":null,"integral":0,"maxPerson":300,"registeredNumber":0}],"pageNum":1,"pageSize":1,"size":1,"startRow":0,"endRow":0,"pages":1,"prePage":0,"nextPage":0,"isFirstPage":true,"isLastPage":true,"hasPreviousPage":false,"hasNextPage":false,"navigatePages":8,"navigatepageNums":[1],"navigateFirstPage":1,"navigateLastPage":1,"firstPage":1,"lastPage":1}}
     */
    @RequestMapping("/selectMyRace")
    public BaseResult selectMyRace(@RequestParam(required = true) Integer pageNum,
                                   @RequestParam(required = true)Integer pageSize,
                                   @RequestParam(required = false) Integer status){
        return userRaceService.selectRaceListByUserId(pageNum,pageSize,status);
    }

    /**
     * showdoc
     * @catalog 赛事/查询单个赛事
     * @title 查询单个赛事
     * @param raceId 必选 int
     * @url /race/api/raceApi/selectRaceById
     * @return {"status":200,"msg":"SUCCESS","data":{"id":1,"raceName":"测试赛事1","registrationStartTime":"2020-04-12 15:04:32","registrationEndTime":"2020-04-17 15:04:43","raceStartTime":"2020-04-21 15:04:46","raceEndTime":"2020-04-23 15:04:51","conditions":"比赛条件","cost":0.0,"address":"测试地址1","rule":"测试规则","organizer":"测试主办方","phone":"18232256987","createTime":"2020-04-11 15:05:50","updateTime":"2020-04-15 18:43:31","raceStatus":1,"integral":0,"maxPerson":300,"registeredNumber":0,"version":0,"imgurl":null,"commitment":null}}
     */
    @RequestMapping("/selectRaceById")
    public BaseResult selectRaceById(@RequestParam(required = true) Integer raceId){
        return raceService.selectById(raceId);
    }
    /**
     * showdoc
     * @catalog 赛事/查询单个报名信息
     * @title 查询单个报名信息
     * @param id 必选 int
     * @url /race/api/raceApi/selectRaceEnterById
     * @return {"status":200,"msg":"SUCCESS","data":{"id":1,"userName":"刘鸿飞","raceId":1,"raceName":"测试赛事1","phone":"18233945873","userId":"158502014539731","status":null,"age":18,"sex":0,"documentType":1,"certificateNumber":"500134199213684978","physicalCertificate":"https://ssyerv1.oss-cn-hangzhou.aliyuncs.com/picture/b24250a49f87406ba230dcdf3367ad84.jpg!sswm,http://125.62.47.85:18080/file/M02/00/01/wKgBf16T1G6ACwPsAADIlD__k9003.jpeg","insuranceCertificate":"https://ssyerv1.oss-cn-hangzhou.aliyuncs.com/picture/b24250a49f87406ba230dcdf3367ad84.jpg!sswm,http://125.62.47.85:18080/file/M02/00/01/wKgBf16T1G6ACwPsAADIlD__k9003.jpeg","note":"https://ssyerv1.oss-cn-hangzhou.aliyuncs.com/picture/b24250a49f87406ba230dcdf3367ad84.jpg!sswm,http://125.62.47.85:18080/file/M02/00/01/wKgBf16T1G6ACwPsAADIlD__k9003.jpeg","createTime":null,"updateTime":null,"orderId":null,"reason":null,"physicalCertificateStr":null,"insuranceCertificateStr":null,"noteStr":null,"registrationStartTime":"2020-04-12 15:04:32","registrationEndTime":"2020-04-17 15:04:43","raceStartTime":"2020-04-21 15:04:46","raceEndTime":"2020-04-23 15:04:51","conditions":"比赛条件","cost":0.0,"address":"测试地址1","rule":"测试规则","organizer":"测试主办方","raceStatus":null,"integral":0,"maxPerson":300,"registeredNumber":0}}
     */
    @RequestMapping("/selectRaceEnterById")
    public BaseResult selectRaceEnterById(@RequestParam(required = true) Integer id){
        return userRaceService.selectRaceEnterById(id);
    }


    /**
     * showdoc
     * @catalog 赛事/取消报名
     * @title 取消报名
     * @param userRaceId 必选 int 取消报名信息id
     * @url /race/api/raceApi/cancelRace
     * @return
     */
    @RequestMapping("/cancelRace")
    public BaseResult cancelRace(@RequestParam(required = true) Integer userRaceId) throws Exception {
       return userRaceService.cancelRace(userRaceId);
    }

    /**
     * showdoc
     * @catalog 赛事/查询是否可以报名
     * @url /race/api/raceApi/selectRaceStatus
     */
    @RequestMapping("/selectRaceStatus")
    public BaseResult selectRaceStatus(@RequestParam(required = true)Integer raceId){
        return raceService.selectRaceStatus(raceId);
    }
}
